//
//  Extension+UIBarButtonItem.swift
//  WJWeiBo
//
//  Created by wangjun on 16/7/19.
//  Copyright © 2016年 wangjun. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    convenience init(title: String?,imgName: String?,target: AnyObject?, action: Selector) {
        self.init()
        
        let button = UIButton()
        if let tit = title {
            
         button.setTitle(tit, forState: UIControlState.Normal)
            button.titleLabel?.font = UIFont.systemFontOfSize(20)
            button.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
            
        }
        
        if let img = imgName {
            
            button.setImage(UIImage(named: img), forState: UIControlState.Normal)
            
        }
        
        button.addTarget(target, action: action, forControlEvents: UIControlEvents.TouchUpInside)
        
        button.sizeToFit()
        self.customView = button
    
    }
    
}